<?php
if ( !defined( "IN_OP" ) )
{
    exit( "You can't access this file directly..." );
}
$ui = new UI();
$conf = new Config();
$db = new db();
include( "admin_menu.php" );
$max_all_percent = $conf->get( "max_all_percent" );
$version = $conf->get( "version" );
if ( $version == "" )
{
    $version = "3.00";
}
if ( $version == "3.06" )
{
    return;
}
echo "<li>系统正从 v{$version} 版升级到 v3.06 版，请稍候......";
$conf->set( "systemcheck_6h", 1 );
$conf->set( "systemcheck_3d", 1 );
$conf->set( "systemcheck_3t", 1 );
$conf->set( "systemcheck_3s1", 1 );
$conf->set( "systemcheck_3s2", 1 );
$conf->set( "systemcheck_3s3", 1 );
$conf->set( "systemcheck_3s4", 1 );
$rs5 = getdb( "select id,percent,upercent_mod from k_user where acl=5 and prev_id=0" );
while ( !$rs5->eof )
{
    $upsen_mod = $rs5->f['upercent_mod'];
    $mpsen5 = max( $max_all_percent, 100 - $rs5->f['percent'] );
    echo "<li>大股东：".$rs5->f['id']."，本线可用成数：".$mpsen5;
    getdb( "update k_user set mpercent=".$mpsen5.", percent_sw=".$upsen_mod." where id=".$rs5->f['id'] );
    $rs4 = getdb( "select id,percent from k_user where acl=4 and prev_id=".$rs5->f['id'] );
    while ( !$rs4->eof )
    {
        $mpsen4 = $mpsen5 - $rs4->f['percent'];
        echo "<li>股东：".$rs4->f['id']."，下线可用成数：".$mpsen4;
        $percent1 = $rs4->f['percent'];
        if ( $upsen_mod == 1 )
        {
            $percent1 = $mpsen5;
        }
        getdb( "update k_user set percent0=".$rs4->f['percent'].", percent1=".$percent1.", mpercent=".$mpsen4." where id=".$rs4->f['id'] );
        $rs3 = getdb( "select id,percent from k_user where acl=3 and prev_id=".$rs4->f['id'] );
        while ( !$rs3->eof )
        {
            $mpsen3 = $mpsen4 - $rs3->f['percent'];
            echo "<li>总代理：".$rs3->f['id']."，下线可用成数：".$mpsen3;
            getdb( "update k_user set percent0=".$rs3->f['percent'].", percent1=".$rs3->f['percent'].", mpercent=".$mpsen3." where id=".$rs3->f['id'] );
            $rs2 = getdb( "select id,percent,mypercent from k_user where acl=2 and prev_id=".$rs3->f['id'] );
            while ( !$rs2->eof )
            {
                getdb( "update k_user set mpercent=".$rs2->f['mypercent'].", percent0=".$rs2->f['percent']." where id=".$rs2->f['id'] );
                echo "<li>代理：".$rs2->f['id']."，总代占成：".$rs2->f['percent']."，代理占成：".$rs2->f['mypercent'];
                $rs2->movenext();
            }
            $rs3->movenext();
        }
        $rs4->movenext();
    }
    $rs5->movenext();
}
$conf->set( "systemcheck_6h", 0 );
$conf->set( "systemcheck_3d", 0 );
$conf->set( "systemcheck_3t", 0 );
$conf->set( "systemcheck_3s1", 0 );
$conf->set( "systemcheck_3s2", 0 );
$conf->set( "systemcheck_3s3", 0 );
$conf->set( "systemcheck_3s4", 0 );
$conf->set( "version", "3.06" );
echo "<li>升级到 v3.06 版完成！";
$ui->footer();
?>